package IO;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
public class charecter {
static String pathwrite;
static String pathread;
private static BufferedReader br;
private static Scanner sc;
static void setpathwrite(String a){
	pathwrite=a;
}
static void setpathread(String a){
	pathread=a;
}
public static void writefile(String pathfile) throws IOException {
	String str;
    FileWriter fw = null;

    BufferedReader br = new BufferedReader(
            new InputStreamReader(System.in));

try {
	fw = new FileWriter(pathfile);
} catch (IOException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
}
System.out.println("nhap van ban ban muon,nhap' stop' de dung:");
do {
    str = br.readLine();
    if (str.compareTo("stop") == 0) {
        break;
    }
    str = str + "\n";  //Dùng để xuống dòng khi nhập xong 1 chuỗi!
    fw.write(str);
} while (str.compareTo("stop") != 0);

fw.close();
}
public static void readfile(String pathfile) throws IOException{
	FileReader fr = new FileReader(pathfile);

	br = new BufferedReader(fr);
    String s;
    //Đọc từng dòng văn bản!
    while ((s = br.readLine()) != null) {
        System.out.println(s);
}

}
public static void main(String[] args) throws IOException{
	sc = new Scanner(System.in);
	System.out.println("nhap duong dan file muon ghi");
	setpathwrite(sc.nextLine());
	writefile(pathwrite);
	System.out.println();
	System.out.println("nhap duong dan fiel ban muon doc");
	setpathread(sc.nextLine());
	readfile(pathread);
}
}